<!--
 * @Description: 
 * @Version: V1.0.0
 * @Author: 周艳凯 484894717@qq.com
 * @Date: 2024-09-27 16:48:55
 * @LastEditors: 周艳凯 484894717@qq.com
 * @LastEditTime: 2024-10-15 14:42:43
 * @FilePath: index.vue
 * Copyright 2024 Marvin, All Rights Reserved. 
 * 2024-09-27 16:48:55
-->
<template>
  <div v-if="visible" :class="classNames">
    <div v-if="!$slots.default" class="arco-spin-icon">
      <slot name="icon"><svgIcon name="loading" :size="size" spin /></slot>
    </div>
    <slot></slot>
    <div v-if="$slots.default && loading" class="arco-spin-mask">
      <div class="arco-spin-mask-icon">
        <div class="arco-spin-icon">
          <slot name="icon"><svgIcon name="loading" :size="size" spin /></slot>
        </div>
        <div class="arco-spin-tip">{{ tip }}</div>
      </div>
    </div>
    <div v-if="hasTip && !$slots.default" class="arco-spin-tip">
      {{ tip }}
    </div>
  </div>
</template>

<script lang="ts">
import { computed, defineComponent, ref } from "vue";
import svgIcon from "../arco-icon/index.vue";
const icon = defineComponent({
  name: "Card",
  options: {
    // 虚拟化节点
    virtualHost: true,
  },
  components: {
    svgIcon,
  },
  props: {
    size: {
      type: Number,
    },
    loading: Boolean,
    dot: Boolean,
    tip: {
      type: String,
      default: "",
    },
    hideIcon: {
      type: Boolean,
      default: false,
    },
  },
  emits: {
    close: () => true,
    afterClose: () => true,
  },
  setup(props, { slots, emit }) {
    const prefixCls = "arco-spin";
    const visible = ref(true);
    const handleClose = () => {
      visible.value = false;
      emit("close");
    };
    const handleAfterLeave = () => {
      emit("afterClose");
    };

    const hasTip = Boolean(slots.tip != null ? slots.tip : props.tip);

    const classNames = computed(() => {
      return [
        prefixCls,
        {
          [`${prefixCls}-loading`]: props.loading,
          [`${prefixCls}-with-tip`]: props.tip && !slots.default,
        },
      ];
    });
    return {
      prefixCls,
      classNames,
      visible,
      hasTip,
      handleClose,
      handleAfterLeave,
    };
  },
});
export default icon;
</script>

<style scoped lang="scss">
@import "./index.scss";
</style>
